package model;

import dao.MesaDAO;
import java.util.ArrayList;

public class Mesa {

        private int id;
        private int chairs;
        private String location;
        private int active;
        private int busy;
        
        private MesaDAO mesaDAO;
               
        public Mesa() {
        	
        	mesaDAO = new MesaDAO();
        	
        }
       
        public int getId() {return id;}
        public String getLocation(){return location;}
        public int getChairs() {return chairs;}
        public int getActive () {return active;}
        public int getBusy() {return busy;}

        public void setId(int id) {this.id = id;}
        public void setChairs(int chairs) {this.chairs = chairs;}
        public void setLocation(String location){this.location = location;}
        public void setActive(int s) {active = s; }
        public void setBusy(int s) {busy = s;}
        
        public boolean register(int chairs, String location, int busy) {
        	Mesa m = new Mesa();
        	
        	m.setChairs(chairs);
        	m.setLocation(location);
        	m.setActive(1);
        	m.setBusy(busy);
        	
        	mesaDAO.create(m);
        	return true;
        }
        
        public boolean modify(int id, int chairs, String location, int busy){
        	Mesa m0 = mesaDAO.select(id);
        	
        	if (m0 != null){
        		
        		Mesa m = new Mesa();
            	
            	m.setChairs(chairs);
            	m.setLocation(location);
            	m.setActive(1);
            	m.setBusy(busy);
            	
            	mesaDAO.update(m);
            	return true;
        	}
        	
        	return false;
        }
        
        public boolean delete(int id) {
        	Mesa m = mesaDAO.select(id);
        	
        	if(m != null){
        		m.delete(id);
        		return true;
        	}
        	return false;
        }
        
        public ArrayList<Mesa> getMesas() {
        	return new ArrayList<Mesa>(mesaDAO.getAll());
        }
       
}
